//package com.power.sifa.aop;
//
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.plf.common.domain.ResponseDTO;
//import com.power.sifa.util.SM4Util;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//
//@Slf4j
//@Aspect
//@Component
//public class DecryptionAspect {
//
//    @Value("${sm4.key}")
//    private String key;
//
//    @Value("${sm4.open}")
//    private boolean open;
//
//    @Resource
//    private ObjectMapper objectMapper;
//
//    @Pointcut("execution(* com..controller.*.*(..)) " +
//            "&& !execution(* com.power.sifa.aop.controller.SMController.*(..))")
//    public void Pointcut() {
//
//    }
//
//    @Around("Pointcut()")
//    public Object encryptResponse(ProceedingJoinPoint joinPoint) throws Throwable {
//        // 执行原方法并获取返回值
//        Object result = joinPoint.proceed();
//
//        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = requestAttributes.getRequest();
//
//        String feignHeader = request.getHeader("X-Feign-Header");
//
//        if ("true".equals(feignHeader)) {
//            log.info("feign接口调用");
//            return result;
//        }
//
//        if (open && result instanceof ResponseDTO) {
//            ResponseDTO dto = (ResponseDTO) result;
//            Object data = dto.getData();
//            if (data != null) {
//
//                String json = objectMapper.writeValueAsString(data);
//                log.warn("ResponseDTO结果：" + json);
//
//                // 调用加密工具类对返回结果进行加密
//                String encryptedResult = SM4Util.encryptEcb(key, json);
//                log.warn("ResponseDTO结果：" + encryptedResult);
//
//                return ResponseDTO.succData(encryptedResult);
//            }
//
//        }
//        return result;
//
//    }
//}